package com.service.calculate;

import com.service.bean.Road_Data;
import com.service.bean.Road_GpsSignal;

/**
 * 状态位计算
 * @author sxc
 *
 */
public class Road_StatusCalculator {	
	
	public void calculate(Road_Data data,Road_GpsSignal signal){
		this.init(data);
		signal.accStatus = this.accStatus;
		signal.gpsStatus = this.gpsStatus;
	}
	
	public void init(Road_Data data){
		this.rawStatus = Long.parseLong(data.rawStatus, 16);
		//第0位：GPS天线状态
		this.gpsAerialStatus = indexOfByte(this.rawStatus,0);
		//第1位：GPS定位状态
		this.gpsStatus = indexOfByte(this.rawStatus,1);
		//第2位：SIM卡服务状态
		this.simStatus = indexOfByte(this.rawStatus,2);
		//第3位：ACC状态
		this.accStatus = indexOfByte(this.rawStatus,3);
		//第4位：电池状态
		this.batteryStatus = indexOfByte(this.rawStatus,4);
	}
	
	protected int indexOfByte(long val, int index) {
		if (((byte) (val >> index) & 0x01) > 0) {
			return 1;
		} else {
			return 0;
		}
	}
	
	
	protected long rawStatus;
	
	/**
	* GPS天线状态
	* 0：GPS天线正常
	* 1：GPS天线断开
	*/
	protected int gpsAerialStatus;
	
	/**
	* GPS定位状态
	* 0：GPS未定位
	* 1：GPS已定位
	*/
	protected int gpsStatus;
	
	/**
	* SIM卡服务状态
	* 0：TODO
	* 1：TODO
	*/
	protected int simStatus;
	
	/**
	* Acc状态
	*/
	protected int accStatus;
	
	/**
	* 电源状态
	* 0：未接电源充电
	* 1：已接电源充电
	*/
	protected int batteryStatus;

}
